package com.example.mvvmdemo.base.paging;

import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;
import androidx.paging.PagingDataAdapter;
import androidx.recyclerview.widget.DiffUtil;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * created by tl
 * created at 2020/9/2
 */
public abstract class BasePagingAdapter<T, VB extends ViewDataBinding> extends PagingDataAdapter<T, BaseViewHolder<VB>> {

    protected int layoutID = 0;

    public BasePagingAdapter(int layoutID, @NotNull DiffUtil.ItemCallback<T> diffCallback) {
        super(diffCallback);
        this.layoutID = layoutID;
    }


    @NonNull
    @Override
    public BaseViewHolder<VB> onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new BaseViewHolder<>(parent, layoutID);
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder<VB> holder, int position) {
        bindDataToView(holder, getItem(position), position);
    }

    //绑定数据到视图
    protected abstract void bindDataToView(BaseViewHolder<VB> holder, T item, int position);

}
